import { prodctCollections, productDetailtions } from "../api/index";
import { Ajax } from "./AjaxConfig";

export const ProdctCollection_List = async () => {
  const res = await Ajax.get(prodctCollections);
  return res.data;
};

export const ProductDetailData = async (id: string | undefined) => {
  const res = await Ajax.get(`${productDetailtions}/${id}`);
  return res.data;
};

export const ProductSearch = async (
  keyword = null,
  nextPage: number | string | null,
  pageSize: number | string | null,
  
) => {
  if (keyword) {
    const res = await Ajax.get(
      `${productDetailtions}?pageNumber=${nextPage}&pageSize=${pageSize}&keyword=${keyword}`
    );
    return {
      data: res.data,
      pagination: JSON.parse(res.headers["x-pagination"]),
    };
  } else {
    const res = await Ajax.get(
      `${productDetailtions}?pageNumber=${nextPage}&pageSize=${pageSize}`
    );
    return {
      data: res.data,
      pagination: JSON.parse(res.headers["x-pagination"])
    };
  }
};
